package com.boot2.core.log;

import com.boot2.core.model.AbstractLog;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;
/**
* @author zhangweilin
* @date 2020/6/1 23:01
* @Description: 系统用户日志开关控制
*/
public class UserLogRegistrar implements ImportBeanDefinitionRegistrar {
 
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
        Map<String, Object> annotationAttributes = annotationMetadata.getAnnotationAttributes(EnableUserLog.class.getName());
        Class<? extends AbstractLog> logModelClass = (Class<? extends AbstractLog>) annotationAttributes.get("logModelClass");
        boolean enable = (boolean) annotationAttributes.get("enable");

        BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(UserLogBeanDefinitionProcessor.class);
        bdb.addPropertyValue("logModelClass", logModelClass);
        bdb.addPropertyValue("enable", enable);
        beanDefinitionRegistry.registerBeanDefinition(UserLogBeanDefinitionProcessor.class.getName(), bdb.getBeanDefinition());
    }
}